package it.mypofolio;

import java.io.File;
import java.io.IOException;

import it.mypofolio.http.CrawlerResult;
import it.mypofolio.http.HttpCrawler;
import it.mypofolio.model.*;
import it.mypofolio.report.Report;
import it.mypofolio.report.ReportPlain;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.http.client.ClientProtocolException;

/**
 * @author  Paolo Cappelletti (Gempliss Srl)
 */
public class Main {
	
	public static void main(String[] args) throws ConfigurationException, ClientProtocolException, IOException {
		String path=System.getProperty("user.dir")+File.separator+"stock.xml";
	
		
		
		HttpCrawler crawler=new HttpCrawler();
		Portfolio pf=new Portfolio();
		pf.load(path);
		
		Report report=new ReportPlain();
		report.start();
		for (int  i = 0;  i<pf.getStockList().size(); i ++) {
			Stock st=pf.getStockList().get(i);
			
			CrawlerResult res=crawler.load(st.getSigla());
			st.setCurrentPrice(res.getQuotation());
			st.setCurrentPriceOra(res.getOra());
			
			report.printStock(st);
			
		}
		report.endCurrent();
		for (int  i = 0;  i<pf.getDoneList().size(); i ++) {
			Done st=pf.getDoneList().get(i);
			report.printDone(st);
			
		}
		report.end();

	}

}
